package mlz.a_charstream;

import org.junit.Test;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

/*
字符输入流
 */
public class FileReaderDemo01 {

    @Test
    public void test01(){
        try(
                //1.创建一个文件字符输入
                FileReader fr = new FileReader("reader1.txt");

        ){
            /*//2.读取一个字符
            int c;
            while((c = fr.read()) != -1){
                System.out.println(c);
            }*/

            //2.读字符数组
            char[] cs = new char[1024];
            //记住每次读取了多少个字符
            int len;
            while((len = fr.read(cs)) != -1){
                //读多少就输出多少
                System.out.println(new String(cs,0,len));
            }
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

}











